<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>添加</title>
	 <link rel="stylesheet" href="./layui/css/layui.css"  media="all">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>添加</legend>
</fieldset>
 
<form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">商品名称</label>
    <div class="layui-input-inline">
      <input type="text" name="goods_name" lay-verify="goods_name" autocomplete="off" placeholder="请输入商品名称" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">商品编号</label>
    <div class="layui-input-inline">
      <input type="text" name="goods_hid" lay-verify="goods_hid" lay-reqtext="商品价格是必填项，岂能为空？" placeholder="请输入商品价格" autocomplete="off" class="layui-input">
    </div>
  </div>

  <form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">价格</label>
    <div class="layui-input-inline">
      <input type="text" name="goods_price" lay-verify="goods_price" autocomplete="off" placeholder="请输入价格" class="layui-input">
    </div>
  </div>

  <form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">上架</label>
    <div class="layui-input-inline">
      <input type="text" name="goods_jia" lay-verify="goods_jia" autocomplete="off" placeholder="请输入上架" class="layui-input">
    </div>
  </div>

   <form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">排序</label>
    <div class="layui-input-inline">
      <input type="text" name="goods_sort" lay-verify="goods_sort" autocomplete="off" placeholder="请输入排序" class="layui-input">
    </div>
  </div>

   <form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">库存</label>
    <div class="layui-input-inline">
      <input type="text" name="goods_sku" lay-verify="goods_sku" autocomplete="off" placeholder="请输入库存" class="layui-input">
    </div>
  </div>

    <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">添加</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>


</body>
</html>
<script src="./layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use(['form', 'layedit', 'laydate'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
   var $=layui.$;
  
 
  //自定义验证规则
  form.verify({
    goods_name: function(value){
      if(value.length < 5){
        return '商品名称至少得5个字符啊';
      }
    }
    ,goods_price: [
      /^[\S]{4,9}$/
      ,'商品价格必须4到9位，且不能出现空格'
    ]
    ,content: function(value){
      layedit.sync(editIndex);
    }
  });
  

  //监听提交
  form.on('submit(demo1)', function(data){
    // layer.alert(JSON.stringify(data.field), {
    //   title: '最终的提交信息'

    // })
           $.ajax({
                  method:'POST',
                  url:'http://127.0.0.1/localhost/day10/php/public/index.php/index/Goodz/getAdd',
                  data:data.field,
                  dataType:'JSON',
                  success:function(){
                      console.log(res)
                      if(res.code==0){
                           layer.alert(res.msg,function(){
                               location.href='show.html'
                           })
                      }
                  }
            })
            return false;
  });
 
  

  
});
</script>